package com.ruoyi.framework.config;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.multipart.MultipartException;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.multipart.support.StandardServletMultipartResolver;

import javax.servlet.http.HttpServletRequest;

/**
 * 自定义 MultipartResolver，处理临时文件删除错误问题
 */
public class CustomMultipartResolver extends StandardServletMultipartResolver {
    private static final Logger log = LoggerFactory.getLogger(CustomMultipartResolver.class);

    @Override
    public MultipartHttpServletRequest resolveMultipart(HttpServletRequest request) throws MultipartException {
        return super.resolveMultipart(request);
    }

    @Override
    public void cleanupMultipart(MultipartHttpServletRequest request) {
        try {
            super.cleanupMultipart(request);
        } catch (Exception e) {
            // 捕获临时文件删除错误，只记录不抛出
            log.warn("Failed to cleanup multipart items: " + e.getMessage());
        }
    }
} 